package com.hundsun.yr.universal.p2p.ui.fragment;

import java.util.List;

import android.support.v4.view.ViewPager;
import android.view.View;

import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.widget.HSTabLayout;
import com.hundsun.yr.universal.library.widget.NoScrollViewPager;
import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.p2p.interactor.impl.TabInvestInteractorImpl;
import com.hundsun.yr.universal.p2p.presenter.base.Presenter;
import com.hundsun.yr.universal.p2p.presenter.impl.BaseTabPresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseFragment;
import com.hundsun.yr.universal.p2p.ui.adapter.ProjectPagerAdapter;
import com.hundsun.yr.universal.p2p.view.base.BaseTabView;



/**
 * @Title: InvestFragment.java 
 * @Description: 投资列表
 * @date 2015-12-1 下午5:01:20 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class InvestFragment extends BaseFragment implements BaseTabView{
	
	private Presenter mPresenter;
	private HSTabLayout mHsTabLayout;
	private NoScrollViewPager noScrollViewPager;
	private ProjectPagerAdapter mAdapter;
	
	@Override
	protected void onFirstUserVisible() {
		// TODO Auto-generated method stub
		mPresenter=new BaseTabPresenterImpl(mContext, this, new TabInvestInteractorImpl());
		mPresenter.initialized();
	}

	@Override
	protected void onUserVisible() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onUserInvisible() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected View getLoadingTargetView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void initViewsAndEvents() {
		// TODO Auto-generated method stub
		noScrollViewPager = (NoScrollViewPager) getActivity().findViewById(R.id.viewpager_project);
		mHsTabLayout = (HSTabLayout) getActivity().findViewById(R.id.tabs_project);
	}
	

	@Override
	protected int getContentViewLayoutID() {
		// TODO Auto-generated method stub
		return R.layout.frag_invest;
	}

	@Override
	protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {
		// TODO Auto-generated method stub
	}

	@Override
	protected boolean isBindEventBusHere() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void initializeViews(List<BaseFragment> fragments, List<View> tabItem, String[] titles) {
		// TODO Auto-generated method stub
		if (noScrollViewPager != null) {
			
			setupViewPager(noScrollViewPager,fragments,titles);
        }
        
	}

	/**
	 * 绑定适配器
	 * @param viewPager
	 * @param fragments
	 * @param titles
	 */
	private void setupViewPager(ViewPager viewPager,List<BaseFragment> fragments,String[] titles) {
		mAdapter = new ProjectPagerAdapter(getChildFragmentManager(),fragments,titles);
		viewPager.setAdapter(mAdapter);
		
		if(fragments.size()>0)noScrollViewPager.setOffscreenPageLimit(fragments.size()-1);
		
		mHsTabLayout.setupWithViewPager(noScrollViewPager);
//		mHsTabLayout.setOnTabChangeListener(new OnTabChangeListener() {
//			
//			@Override
//			public void onTabSelected(int position) {
//				// TODO Auto-generated method stub
//				
//			}
//		});
	}

	@Override
	public <T> void initializeViews(String task_name, T data) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public <T> void initializeError(String task_name, T data) {
		// TODO Auto-generated method stub
		
	}

}
